home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 973 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.9 KB  |  111 lines

  1. Path: news.sprintlink.net!datalytics!news
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Rogue Wave bug? / How buggy is Rogue Wave?
  5. Date: 8 Jan 1996 18:49:09 GMT
  6. Organization: Datalytics, Inc
  7. Message-ID: <4crov6$h4r@gold.datalytics.com>
  8. References: <DKo7KB.6KL@unx.sas.com>
  9. NNTP-Posting-Host: pc071.datalytics.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. sasrag@ramanujn.unx.sas.com (Russell Gonsalves) wrote:
  16. >/*
  17. >
  18. >Here's the program to try:
  19. >
  20. >The bug?
  21. >
  22. >It seems to badly handle null-strings.  The last
  23. >print still prints yy.  While test.isNull() is
  24. >aware that the string is a null-terminated string,
  25.  
  26. Actually, isNull() is only aware that the string has a length 
  27. of zero.  That difference is the crux of the problem as 
  28. explained below.
  29.  
  30. >such a RWCString cast to const char * does not
  31. >point to "".  This appears to defeat the otherwise
  32. >seamless and elegant conversion between RWCStrings
  33. >and character pointers.
  34. >
  35. >If you have RW could you try this out, and tell
  36. >me if your version produces similar results.
  37. >
  38. I have Tools.h++ v6.1 and I got similar results.  I was 
  39. surprised at the behavior.  Here is the relevent code from the 
  40. implementation.  The problem is that, since there is no other 
  41. RWCString referencing the same RWCStringRef, operator = only 
  42. sets nchars_ (the number of characters in the string) to zero.  
  43. It should also assign a null terminator to data_[0].
  44.  
  45. RWCString&
  46. RWCString::operator=(const char* cs)
  47. {
  48. [snip]
  49.     if (pref()->references() == 1) {
  50.       pref()->nchars_ = 0;
  51.       // should also include this statement:
  52.       *data_ = '\0';
  53.     } else {
  54. [snip]
  55.     }
  56.     return *this;
  57. [snip]
  58. }
  59.  
  60.  
  61. >What are your experiences with this library.  We've
  62. >just started to use it, and quite frankly I'm a
  63. >little surprised by this bug.
  64. >
  65. I have nothing (until now) but praise for the Tools.h++ 
  66. library.  They have done many slick things with the language 
  67. (consider the RWCSubString extraction using function call 
  68. syntax on an RWCString), and have implemented sound, complete, 
  69. and properly OO classes.
  70.  
  71. I regularly use RWCString and haven't encountered a problem 
  72. with the incorrect behavior you observed.  That doesn't mean I 
  73. won't.  It is a wise purchase.  You will readily recoup the 
  74. cost in enhanced productivity.
  75.  
  76. Despite this problem, I would still recommend the library.  If 
  77. you buy rights to the source code, as we have, you can make 
  78. this fix yourself (not that you should have to, mind you).
  79.  
  80. >#include <iostream.h>
  81. >#include <rw/cstring.h>
  82. >
  83. >static void print(const char * p)
  84. >{
  85. >   cout << "String:\"" << p << "\"" << endl;
  86. >}
  87. >
  88. >main()
  89. >{
  90. >   RWCString test;
  91. >
  92. >   test = "abc";
  93. >   print(test);
  94. >   test = "xyz";
  95. >   print(test);
  96. >   test = "yy";
  97. >   print(test);
  98. >   test = "";
  99. >   print(test);
  100. >}
  101. >
  102.  
  103.  
  104. -- 
  105. Robert Stewart        | My opinions are usually my own.
  106. Datalytics, Inc.
  107. (513)226-7700
  108. stew@datalytics.com
  109.  
  110.  
  111.